<template>
    <div class="bg">
        <div class="login-tit">智慧停车后台管理系统</div>
        <div class="login-wrap">
            <el-input
                placeholder="请输入用户名"
                @keydown.enter.native.prevent.stop="loginClick"
                v-model="username">
                <img src="../../assets/images/account.png" slot="prefix" width="19" height="21" class="login-img">
            </el-input>
            <el-input
                class="pass-box"
                placeholder="请输入密码"
                v-model="password"
                @keydown.enter.native.prevent.stop="loginClick"
                type="password">
            <img src="../../assets/images/pass.png" slot="prefix" width="19" height="21" class="login-img">
            </el-input>
            <el-button class="login-btn" @click="loginClick">登录</el-button>
        <!-- <el-button class="login-btn1" @click="loginClick">注册</el-button> -->
        </div>
    </div>
</template>

<script>
export default {
    name: 'index',
    data () {
        return {
            username: 'admin',
            password: '123456'
        }
    },
    methods: {
        async loginClick () {
            if (!this.username) {
                return this.$message.error('请输入用户名')
            }
            if (!this.password) {
                return this.$message.error('请输入密码')
            }
            try{
                const { data : res } = await this.$api.login({
                    username: this.username,
                    password: this.password
                })
                if(res.code) return this.$message.error(res.msg)
                this.$message.success(res.msg)
                const { 
                    token,
                    username,
                    isAdmin,
                    roleId
                } = res.result
                localStorage.token = token
                localStorage.isAdmin = isAdmin
                localStorage.username = username
                localStorage.roleId = roleId
                this.$store.state.adminId = token
                this.$router.push('/home')
            }catch(e){ 
                console.log(e);
            }
            // this.$store.dispatch('login', {
            //   // username: 'admin_area',
            //   // username: 'admin_community',
            //   // password: '123456'
            //   username: this.username,
            //   password: this.password
            // }).then(res => {
            //   this.$message({
            //     message: '登录成功',
            //     type: 'success',
            //     duration: 1500,
            //     onClose: () => {
            //       this.$router.push('/')
            //     }
            //   })
            // })
        }
    }
}
</script>

<style scoped>
.bg {
  width: 100%;
  height: 100vh;
  background: url("../../assets/images/login_bg.png") no-repeat;
  background-size: 100% 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
  .login-tit{
    font-size: 48px;
    color: #ffffff;
    margin-bottom: 90px;
  }
  .login-wrap{
    width: 558px;
    background-color: rgba(255, 255, 255, 0.1);
    padding: 86px 96px;
    box-sizing: border-box;
    border-radius: 30px;
  }
  .login-img{
    margin-top: 10px;
    padding: 0 5px;
    margin-right: 5px;
  }
 >>>.el-input__inner{
  padding-left: 40px!important;
}
  .pass-box{
    margin: 35px 0;
  }
  .login-btn {
    width:366px;
    height:56px;
    background:linear-gradient(0deg,rgba(151,171,185,1),rgba(239,248,249,1));
    border-radius:4px;
    margin-top: 40px;
    font-size: 20px;
    color: #39546A;
  }
  .login-btn1 {
    width:366px;
    height:56px;
    background:linear-gradient(0deg,rgba(151,171,185,1),rgba(239,248,249,1));
    border-radius:4px;
    margin-top: 20px;
    font-size: 20px;
    color: #39546A;
    margin-left: 0 !important;
  }
</style>
